import HRDCCustomerApi from '@/api/HRDCCustomer.api.js'
import visibvleTreeList from '../HRDC-common/visibleTreeList.vue'
export default {
  data () {
    return {
      dolderNames: '',
      salesIds: [],
      treeData: []
    }
  },
  components: {
    visibvleTreeList
  },
  computed: {
    tipIsShow () {
      if (this.dolderNames) {
        return true
      } else {
        return false
      }
    }
  },
  created () {
    this.getVisibleTreeList()
  },
  methods: {
    // 设置表头
    getTableColumns (arr) {
      const tableColumns = {
        selection: {
          type: 'selection',
          width: 60,
          align: 'center',
          fixed: 'left'
        },
        // code: {
        //   title: '员工编号',
        //   minWidth: 150,
        //   align: 'center',
        //   key: 'code'
        // },
        // code1: {
        //   title: '职位',
        //   minWidth: 150,
        //   align: 'center',
        //   key: 'code'
        // },
        userName: {
          title: '姓名',
          minWidth: 100,
          align: 'center',
          key: 'userName'
        },
        customerCount: {
          title: '私有客户数',
          minWidth: 110,
          align: 'center',
          key: 'customerCount'
        },
        oTypeCount: {
          title: 'O类客户数',
          minWidth: 110,
          align: 'center',
          key: 'oTypeCount'
        },
        aTypeCount: {
          title: 'A类需求',
          minWidth: 100,
          align: 'center',
          key: 'aTypeCount'
        },
        bTypeCount: {
          title: 'B类需求',
          minWidth: 100,
          align: 'center',
          key: 'bTypeCount'
        },
        cTypeCount: {
          title: 'C类需求',
          minWidth: 100,
          align: 'center',
          key: 'cTypeCount'
        },
        dTypeCount: {
          title: 'D类需求',
          minWidth: 100,
          align: 'center',
          key: 'dTypeCount'
        },
        toDeliveryCount: {
          title: '需交付需求数',
          minWidth: 120,
          align: 'center',
          key: 'toDeliveryCount'
        },
        deliveriedCount: {
          title: '已交付需求数',
          minWidth: 120,
          align: 'center',
          key: 'deliveriedCount'
        },
        deliveriedAmt: {
          title: '签约金额',
          minWidth: 100,
          align: 'center',
          key: 'signedAmt'
        },
        signedAmt: {
          title: '交付金额',
          minWidth: 100,
          align: 'center',
          key: 'deliveriedAmt'
        }
      }
      let data = []

      arr.forEach(col => data.push(tableColumns[col]))

      return data
    },
    // 获取当前角色可见的销售人员
    getVisibleTreeList () {
      HRDCCustomerApi.GetVisibleTreeList().then(res => {
        console.log(res)
        this.treeData = res.data.data
      })
    },
    chooseSaler () {
      this.$refs.treeModal.show()
    },
    salersClear () {
      console.log(22222)
      this.salesIds = []
      this.getVisibleTreeList()
    },
    getSalerId (val) {
      console.log(val)
      let idArr = []
      let nameArr = []
      val.forEach(item => {
        if (item.type === "4") {
          idArr.push(item.id)
          nameArr.push(item.title)
        }
      })
      this.salesIds = idArr
      this.dolderNames = nameArr.join(',')
    }
  }
}
